<template>
  <div>
    <WriteForm
      :formType="3"
      :form-key="formKey"
      :reviewer-key="reviewerKey"
      v-if="formKey && canAppraise"
    />

    <el-result
      :title="$t('common.tip')"
      icon="error"
      :subTitle="$t('form.evaluation.repeatEvaluation')"
      v-if="canAppraise == false"
    ></el-result>
  </div>
</template>
<script setup lang="ts">
import WriteForm from "./index.vue";
import { useRoute } from "vue-router";
import { onBeforeMount, ref } from "vue";
import { getReviewerInfo } from "@/api/evaluation/reviewer";
import { evaluationUser } from "@/views/formgen/components/GenerateForm/hooks/useEvaluationUser";
import { Session } from "@/utils/storage";
import { tokenKey } from "@/utils/auth";

const { appraiseUserList, isEvaluated } = evaluationUser;

const formKey = ref();

const canAppraise = ref(true);

const reviewerKey = ref("");

onBeforeMount(() => {
  const route = useRoute();
  const key = route.params.key as string;
  getReviewerInfo(key).then(res => {
    if (res.data) {
      appraiseUserList.value = res.data.appraiseUserList?.map(item => item.user) || [];
      isEvaluated.value = true;
      canAppraise.value = res.data.canAppraise;
      formKey.value = res.data.formKey;
      reviewerKey.value = res.data.reviewerKey;
      Session.set(tokenKey, res.data.token);
    } else {
      canAppraise.value = false;
    }
  });
});
</script>

<style scoped lang="scss"></style>
